<?php
/*
usage:生成github的代码
* 初始化
  * 数据库初始化脚本修改
_xp_files/product_to_github/05.project_static_source(static_code)/application/admin/command/Install/fastadmin_addition.sql
  * 修改安装的系统名称
_xp_files/product_to_github/05.project_static_source(static_code)/application/admin/command/Install/zh-cn.php
  * 修改插件中的addons.php
_xp_files/product_to_github/05.project_static_source(static_code)/application/extra/addons.php
  * 修改插件中的addons.js
_xp_files/product_to_github/05.project_static_source(static_code)/public/assets/js/addons.js

* 运行脚本，复制到chenshiming0802\thinkphp_fastadmin_signin
php xp_product_console_generate_product_to_github.php csmsignin thinkphp_fastadmin_signin
*/
$pluginname = $argv[1]; // 默认为 'csmsignin'
$targetproduct = $argv[2]; // 默认为 'thinkphp_fastadmin_signin'

include "xp_project_function.php";

$basepath = "_xp_files/product_to_github/";
$fastadmin_source = $basepath."01.fastadmin_source(copy_from_fastdmin_com)/";
$stardard_update_install = $basepath."02.stardard_update_install(static_code)/";
$revert_install_source = $basepath."03.revert_install_source(static_code)/";
$project_source = $basepath."04.project_source(copy_from_project)/";
$project_static_source = $basepath."05.project_static_source(static_code)/";
$dist_thinkphp_fastadmin_product = $basepath."06.dist_thinkphp_fastadmin_product(copy_to_github)/{$targetproduct}/";


// fill project_source (this code copy from xp_console_package_plugin.php)
$dist_plugin = $project_source;
deleteDirectory($dist_plugin);
xcopy("addons/{$pluginname}","{$dist_plugin}addons/{$pluginname}");
$modules = ["admin","api","index",$pluginname];
foreach($modules as $module){
    xcopy("application/{$module}/controller/{$pluginname}","{$dist_plugin}application/{$module}/controller/{$pluginname}");
    xcopy("application/{$module}/lang/zh-cn/{$pluginname}","{$dist_plugin}/application/{$module}/lang/zh-cn/{$pluginname}");
    xcopy("application/{$module}/model/{$pluginname}","{$dist_plugin}/application/{$module}/model/{$pluginname}");
    xcopy("application/{$module}/validate/{$pluginname}","{$dist_plugin}/application/{$module}/validate/{$pluginname}");
    xcopy("application/{$module}/view/{$pluginname}","{$dist_plugin}/application/{$module}/view/{$pluginname}");
}

xcopy("public/assets/addons/{$pluginname}","{$dist_plugin}/public/assets/addons/{$pluginname}");
xcopy("public/assets/js/backend/{$pluginname}","{$dist_plugin}/public/assets/js/backend/{$pluginname}");
xcopy("public/assets/js/frontend/{$pluginname}","{$dist_plugin}/public/assets/js/frontend/{$pluginname}");


xcopy($fastadmin_source,$dist_thinkphp_fastadmin_product);
xcopy($stardard_update_install,$dist_thinkphp_fastadmin_product);
xcopy($revert_install_source,$dist_thinkphp_fastadmin_product);
xcopy($project_source,$dist_thinkphp_fastadmin_product);
xcopy($project_static_source,$dist_thinkphp_fastadmin_product);

// unlink($dist_thinkphp_fastadmin_product."/application/admin/command/Install/install.lock");
// unlink($dist_thinkphp_fastadmin_product."/public/manage.php");

echo "success";
